package com.decent.ejfadmin.user.controller;


import cn.decent.component.shiro.entity.Admin;
import cn.decent.component.shiro.service.AdminService;
import com.decent.ejfadmin.common.bean.MessageBean;
import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.common.bean.UserFeedback;
import com.decent.ejfadmin.user.service.UserFeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * 会员意见反馈
 *
 * @author weicx
 * @date 2018/08/20
 */
@RestController
@Slf4j
@RequestMapping("/UserFeedbackController")
public class UserFeedbackController {
    @Autowired
    private UserFeedbackService userFeedbackService;
    @Autowired
    private AdminService adminService;

    /**
     * 查询会员意见反馈
     *
     * @param userFeedback 会员意见反馈
     * @param page         分页
     * @return MemberMessage
     */
    @RequestMapping("/queryFeedbackPage")
    public Page queryFeedbackPage(Page page, UserFeedback userFeedback) {
        try {
            return userFeedbackService.queryFeedbackPage(page, userFeedback);
        } catch (Exception e) {
            log.warn("查询会员意见反馈异常: [{}]", e);
            page.setResultList(new ArrayList<>());
            page.setTotal(0);
            return page;
        }
    }

    /**
     * 修改会员反馈
     *
     * @param userFeedback 会员意见反馈
     * @return 修改行数
     */
    @RequestMapping("modifyFeedback")
    public MessageBean modifyFeedback(UserFeedback userFeedback) {
        try {
            if (userFeedback.getId() == null) {
                return MessageBean.fail("请选择会员意见");
            }
            if (userFeedback.getStatus() == null) {
                return MessageBean.fail("请选择具体操作");
            }
            Admin admin = adminService.getCurrentAdmin();
            userFeedback.setAdmin(admin.getName());
            return userFeedbackService.modifyFeedback(userFeedback);
        } catch (Exception e) {
            log.warn("[{}] 修改会员反馈异常: [{}]", userFeedback, e);
            return MessageBean.fail();
        }
    }


}
